#include "logc/logc.h"
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#endif

#ifdef _WIN32
unsigned int __stdcall ThreadFun(PVOID lpParam)
{
    log_info("thread id: %lu\n", GetCurrentThreadId());
    return 0;
}
#endif

int main()
{
    FILE *fp = fopen("log.txt", "a+");
    if (fp == NULL)
    {
        printf("create log file failed.\n");
        return -1;
    }

    // 设置日志级别(在终端打印)
    log_set_level(LOG_TRACE);

    // 设置日志级别(在文件中打印)
    log_add_fp(fp, LOG_INFO);

    log_trace("start trace.");
    log_debug("start debug.");
    log_info("start info.");
    log_warn("start warn.");
    log_error("start error.");
    log_fatal("start fatal");

    // 支持参数打印
    log_info("number is %d, string is %s", 10010, "helloword");

    log_info("start thread.");

    // 创建线程
#ifdef _WIN32
    HANDLE handle1 = (HANDLE)_beginthreadex(NULL, 0, ThreadFun, NULL, 0, NULL);
    HANDLE handle2 = (HANDLE)_beginthreadex(NULL, 0, ThreadFun, NULL, 0, NULL);

    WaitForSingleObject(handle1, INFINITE);
    WaitForSingleObject(handle2, INFINITE);
#endif

    log_info("end thread.");

    fclose(fp);

    return 0;
}